home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / terminal / pr4w32 / pub / uuencode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-06  |  1.3 KB  |  60 lines

  1. /* uuencode.c - convert files to ascii-encoded form
  2.  * Usage: uuencode [filename] < infile
  3.  *
  4.  * If [filename] isn't specified, "/dev/stdout" is the default.  This allows
  5.  * use of my uudecode as a pipeline filter.
  6.  *
  7.  * Written and placed in the public domain by Phil Karn, KA9Q
  8.  * 31 March 1987
  9.  */
  10. #include <stdio.h>
  11. #define LINELEN 45
  12.  
  13. main(argc,argv)
  14.  
  15.    int argc;
  16.    char *argv[];
  17.  
  18. {
  19.    char      linebuf[LINELEN];
  20.    register  char *cp;
  21.    register  int linelen;
  22.    FILE      *in, *out;
  23.  
  24.    if (argc < 3)
  25.    {
  26.       printf("\n Usage: uuencode infile outfile\n");
  27.       return(0);
  28.    }
  29.  
  30.    in  = fopen(argv[1],"rb");
  31.    out = fopen(argv[2],"w");
  32.  
  33.    fprintf(out,"begin 0666 %s\n",argv[1]);
  34.  
  35.    for(;;)
  36.    {
  37.       linelen = fread(linebuf,1,LINELEN,in);
  38.  
  39.       if (linelen <= 0)
  40.          break;
  41.  
  42.       fputc(' ' + linelen,out);          // Record length
  43.  
  44.       for(cp = linebuf; cp < &linebuf[linelen]; cp += 3)
  45.       {
  46.          fputc(' ' + ((cp[0] >> 2) & 0x3f),out);
  47.          fputc(' ' + (((cp[0] << 4) & 0x30) | ((cp[1] >> 4) & 0xf)),out);
  48.          fputc(' ' + (((cp[1] << 2) & 0x3c) | ((cp[2] >> 6) & 0x3)),out);
  49.          fputc(' ' + (cp[2] & 0x3f),out);
  50.       }
  51.       fputc('\n',out);
  52.    }
  53.    fprintf(out," \n");  /* 0-length null record */
  54.    fprintf(out,"end\n");
  55.  
  56.    fclose(out);
  57.    fclose(in);
  58.  
  59. }
  60.